package org.urchr.beorganized.api.impl.xml;

import org.urchr.beorganized.api.base.PrivateBaseAPIServlet;
import org.urchr.beorganized.api.impl.SaveNote;
import org.urchr.beorganized.dao.XMLDocumentBuilder;
import org.urchr.beorganized.dao.errors.DBErrorException;
import org.urchr.beorganized.dao.errors.GeneralException;

public class CheckSaveResult extends PrivateBaseAPIServlet {

	@Override
	protected void doProcessPrivate() throws GeneralException {
		Object result = Import.results.get(getParameter("rnd"));
		if(result==null)
			throw new DBErrorException();
		Import.results.remove(getParameter("rnd"));
		if(result instanceof GeneralException)
			throw (GeneralException)result;
		XMLDocumentBuilder doc = new XMLDocumentBuilder();
		doc.getRootElement("note").setAttribute("id", result.toString());
		sendNode(doc.getRootElement());
	}

}
